let list4 = [
  {
    name: "好先森1",
    id: 1,
  },
  {
    name: "好先森1",
    id: 2,
  },
  {
    name: "好先森2",
    id: 3,
  },
  {
    name: "好先森3",
    id: 3,
  },
];

// filter + map 根据某个属性去重
const fn1 = (arr, key) => {
  let mapping = new Map();
  return arr.filter((item) => {
    if (!mapping.has(item[key].toString())) {
      mapping.set(item[key].toString(), "anything");
      return true;
    }
  });
};

// filter+includes 根据某个属性去重
const fn2 = (arr, key) => {
  let curList = [];
  return arr.filter((item) => {
    if (!curList.includes(item[key].toString())) {
      curList.push(item[key].toString());
      return true;
    }
  });
};

console.log(fn2(list4, "id"));
